class: title-slide, right, top background-image: url(data:image/png;base64,#img/axsome_logo.png) background-size: 40%, cover
.right-column[ # Module 1: R, What Is It Good For? ### Introduction and Overview **Graham Eglit**<br> Axsome Therapeutics<br> Fall 2024 ] --- class: inverse, center, middle # Introduction ---- <svg viewBox="0 0 581 512" style="position:relative;display:inline-block;top:.1em;fill:white;height:3em;" xmlns="http://www.w3.org/2000/svg"> <path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"></path></svg> --- # .center[Why R?] .pull-left[ - Free <br> <br> - Open Source <br> <br> - Large User Base/Community <br> <br> - Cutting-Edge Statistics <br> <br> - Reproducibility <br> <br> - Version Control/Collaboration <br> <br> - Communication <br> <br> ] .pull-right[ <img src="data:image/png;base64,#img/hex_rstudio.png" width="65%"/> ] --- class: center # Growth of R .panelset[ .panel[.panel-name[Jobs - 2017 & 2019] <img src="data:image/png;base64,#img/mod1/pop_jobs.png" width="38.5%"/> <figcaption>Figure from [The Popularity of Data Science Software](https://r4stats.com/articles/popularity/)</figcaption> ] <!----> .panel[.panel-name[User Base] <img src="data:image/png;base64,#img/mod1/pop_tidy.png" width="50%"/> <figcaption>Figure from [R's Demise is Highly Overblown](https://www.alfredogmarquez.com/2019/12/29/r-s-demise-higly-overblown/)</figcaption> ] <!----> .panel[.panel-name[Primary Tool] <img src="data:image/png;base64,#img/mod1/pop_use.png" width="47%"/> <figcaption>Figure from [The Popularity of Data Science Software](https://r4stats.com/articles/popularity/)</figcaption> ] <!----> .panel[.panel-name[1995 - 2016 Articles] <img src="data:image/png;base64,#img/mod1/pop_time.png" width="36%"/> <figcaption>Figure from [The Popularity of Data Science Software](https://r4stats.com/articles/popularity/)</figcaption> ] <!----> .panel[.panel-name[2018 Articles] <img src="data:image/png;base64,#img/mod1/pop_articles.png" width="33.5%"/> <figcaption>Figure from [The Popularity of Data Science Software](https://r4stats.com/articles/popularity/)</figcaption> ] <!----> ] <!--end of panelset--> --- # .center[You Can Do Cool Stuff In R] .pull-left[ <br> <br> - [Generative Art](https://www.data-imaginist.com/art) <br> <br> - [Websites](https://www.lucymcgowan.com/) <br> <br> - [Data Visualization](https://www.cedricscherer.com/top/dataviz/) <br> <br> - [Resumes](https://twitter.com/NicholasStrayer/status/1178754342289121280/photo/1) <br> <br> ] .pull-right[ <br> <br> - [Books](https://r4ds.had.co.nz/index.html) <br> <br> - [Slides](https://spcanelon.github.io/xaringan-basics-and-beyond/) <br> <br> - [Shiny Apps](https://shiny.rstudio.com/gallery/) <br> <br> - [Interactive Visualizations](https://rpsychologist.com/pvalue/) <br> <br> ] --- # .center[Why Not R?] .left-column[ <br> <br> - Learning Curve <br> <br> - Ever-Expanding Ecosystem <br> <br> - Validation? <br> <br> - Opinionated <br> <br> ] .right-column[ <img src="data:image/png;base64,#img/mod1/packages.png" width="80%"/> .caption[ Figure from [Gergely Daróczi](https://gist.github.com/daroczig/3cf06d6db4be2bbe3368) ] ] --- class: inverse, middle, center # Overview ---- <svg viewBox="0 0 581 512" style="position:relative;display:inline-block;top:.1em;fill:white;height:3em;" xmlns="http://www.w3.org/2000/svg"> <path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"></path></svg> --- # .center[History of R] .right-column[ - R is a descendent of the S programming language - S was developed at the Bell Telephone Laboratories in 1976 - S was designed for data analysis, but with the goal that *users* would become *developers* - In 1988, the third version of S (S3) was rewritten in C and began to resemble the R language in use today. - S4 was later released in 1998 - R was created in 1991 by Ross Ihaka and Robert Gentleman - R was released using a GNU General Public License in 1995, ensuring that it would remain free and open source - In 2001, R version 1.0.0 was released to the public - The most recent version of R is 4.2.0, which was released on 2022-04-22 ] .left-column[ <img src="data:image/png;base64,#img/mod1/gentleman.png" width="70%"/> <figcaption>Robert Gentleman<figcaption> <img src="data:image/png;base64,#img/mod1/ihaka.jpg" width="80%"/> <figcaption>Ross Ihaka<figcaption> ] --- # .center[R vs. R Studio] .pull-left[.center[ ## R .bullets[ A programming langauge <br> A console <br> Runs computations <br> ] <img src="data:image/png;base64,#img/mod1/r_console.jpg" width="40%"/> <br> DON'T USE THIS ONE! ]] .pull-left[.center[ ## R Studio An add-on that integrates with R <br> Creates a more user-friendly interface <br> An **Integrated Development Environment (IDE)** <img src="data:image/png;base64,#img/mod1/r_studio.png" width="32%"/> <br> USE THIS ONE! ]] --- class: center # R vs. R Studio .middle[ <img src="data:image/png;base64,#img/mod1/modern_dive.png" width="75%"/> .caption[ Figure from [Modern Dive](https://moderndive.com/1-getting-started.html) ] ] --- class: center, middle # Let's Tour R and R Studio! <img src="data:image/png;base64,#img/mod1/tour.jpg" width="75%"/> --- .center[ # R Syntaxes ] .pull-left[ ## Base R - The original R syntax - All the functionality that's pre-loaded when you open an R session - Core packages: `base`, `compiler`, `datasets`, `graphics`, `grDevices`, `grid`, `methods`, `parallel`, `splines`, `stats`, `stats4`, `tcltk`, `tools`, `translations`, `utils` .center[ <img src="data:image/png;base64,#img/mod1/artofr.jpg" width="25%"/> ] ] .pull-right[ ## Tidyverse - Released in 2016 - A suite of add-on packages that follow a coherent programming style - Core packages: `dplyr`, `ggplot2`, `tidyr`, `readr`, `purrr`, `tibble`, `stringr`, `forcats` <br> <br> .center[ <img src="data:image/png;base64,#img/mod1/r4ds.jpg" width="25%"/> ] ] --- .center[ # Objects, Functions, and Packages ] .pull-left[ - **Object** - A named listing of information that you can call up - can be a single number, a plot, a dataframe, a model, etc. - in R, everything is an object! - **Function** - an encoded set of instructions for acting upon objects - e.g., `mean`, `sum`, `plot`, etc. - functions are also objects! - **Package** - a collection of functions that are bundled together - typically, functions in a pacakge accomplish a similar set of tasks - e.g., `ggplot2` is a package focused on data visualization ] .pull-right[ ```r x <- c(3, 7, 5) x ``` ``` ## [1] 3 7 5 ``` ```r sum(x) ``` ``` ## [1] 15 ``` ```r mean(x) ``` ``` ## [1] 5 ``` ] --- .center[ # Where Do Packages Come From? ] .pull-left[ - Packages are developed by R users - They're submitted and stored on the Comprehensive R Archive Network (CRAN) for public use - Other R users can then download those packages onto their own computers (using `install.packages`) - To use the functions within a package, the package needs to be loaded during an R session (using `require` or `library`) ] .pull-right[ <br> <br> <br> ```r install.packages("tidyverse") ``` <br> ```r require(tidyverse) library(tidyverse) ``` ] .center[ <img src="data:image/png;base64,#img/mod1/cran.png" width="60%"/> ] --- class: inverse, center, middle # Concluding Remarks ---- <svg viewBox="0 0 581 512" style="position:relative;display:inline-block;top:.1em;fill:white;height:3em;" xmlns="http://www.w3.org/2000/svg"> <path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"></path></svg> --- .center[ # Where have we been? ] .pull-left[ <br> - R is a free and **open source** statistical software - **R users** are also **R developers** - R developers create **packages** of **functions** that are uploaded onto **CRAN** - We (R users) can download those packages from CRAN onto our computers - R studio is an **integrated development environment** that has helpful tools and features that make using R easier - We'll use R Studio to communicate with R and use the cool stuff that R developers have created to **create cool stuff** of our own ] .pull-right[ <br> .center[ <img src="data:image/png;base64,#img/mod1/hair.jpg" width="70%"/> ] ] --- <br> .center[ <img src="data:image/png;base64,#img/mod1/next.jpg" width="55%"/> ] .left[ ### A quick journey through Base R... ] .right[ ### ...And then off to the Tidyverse ]